/*
 * Copyright [2022] [https://www.xiaonuo.vip]
 *
 * Snowy采用APACHE LICENSE 2.0开源协议，您在使用过程中，需要注意以下几点：
 *
 * 1.请不要删除和修改根目录下的LICENSE文件。
 * 2.请不要删除和修改Snowy源码头部的版权声明。
 * 3.本项目代码可免费商业使用，商业使用请保留源码和相关描述文件的项目出处，作者声明等。
 * 4.分发源码时候，请注明软件出处 https://www.xiaonuo.vip
 * 5.不可二次分发开源参与同类竞品，如有想法可联系团队xiaonuobase@qq.com商议合作。
 * 6.若您的项目无法满足以上几点，需要更多功能代码，获取Snowy商业授权许可，请在官网购买授权，地址为 https://www.xiaonuo.vip
 */
package vip.xiaonuo.biz.modular.watchtask.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import vip.xiaonuo.biz.modular.watchtask.entity.Task;
import vip.xiaonuo.biz.modular.watchtask.entity.TaskAuditRecord;
import vip.xiaonuo.biz.modular.watchtask.entity.TaskLog;
import vip.xiaonuo.biz.modular.watchtask.param.*;
import vip.xiaonuo.biz.modular.watchtask.result.TaskAssigmentUser;
import vip.xiaonuo.biz.modular.watchtask.service.TaskAssignmentService;
import vip.xiaonuo.biz.modular.watchtask.service.TaskAuditRecordService;
import vip.xiaonuo.biz.modular.watchtask.service.TaskLogService;
import vip.xiaonuo.biz.modular.watchtask.service.TaskService;
import vip.xiaonuo.common.annotation.CommonLog;
import vip.xiaonuo.common.pojo.CommonResult;
import vip.xiaonuo.common.pojo.CommonValidList;

import javax.annotation.Resource;
import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;

/**
 * 任务表控制器
 *
 * @author H
 * @date  2025/11/19 14:24
 */
@Api(tags = "任务表控制器")
@ApiSupport(author = "SNOWY_TEAM", order = 1)
@RestController
@Validated
public class TaskController {

    @Resource
    private TaskService taskService;
    @Resource
    private TaskAuditRecordService taskAuditRecordService;
    @Resource
    private TaskAssignmentService taskAssignmentService;
    @Resource
    private TaskLogService taskLogService;

    /**
     * 获取任务表分页
     *
     * @author H
     * @date  2025/11/19 14:24
     */
    @ApiOperationSupport(order = 1)
    @ApiOperation("获取任务表分页")
    @GetMapping("/biz/task/page")
    public CommonResult<Page<Task>> page(TaskPageParam taskPageParam) {
        return CommonResult.data(taskService.page(taskPageParam));
    }

    /**
     * 添加任务表
     *
     * @author H
     * @date  2025/11/19 14:24
     */
    @ApiOperationSupport(order = 2)
    @ApiOperation("添加任务表")
    @CommonLog("添加任务表")
    @PostMapping("/biz/task/add")
    public CommonResult<String> add(@RequestBody @Valid TaskAddReq taskAddReq) {
        taskService.add(taskAddReq);
        return CommonResult.ok();
    }

    /**
     * 编辑任务表
     *
     * @author H
     * @date  2025/11/19 14:24
     */
    @ApiOperationSupport(order = 3)
    @ApiOperation("编辑任务表")
    @CommonLog("编辑任务表")
    @PostMapping("/biz/task/edit")
    public CommonResult<String> edit(@RequestBody @Valid TaskEditParam taskEditParam) {
        taskService.edit(taskEditParam);
        return CommonResult.ok();
    }

    /**
     * 删除任务表
     *
     * @author H
     * @date  2025/11/19 14:24
     */
    @ApiOperationSupport(order = 4)
    @ApiOperation("删除任务表")
    @CommonLog("删除任务表")
    @SaCheckPermission("/biz/task/delete")
    @PostMapping("/biz/task/delete")
    public CommonResult<String> delete(@RequestBody @Valid @NotEmpty(message = "集合不能为空")
                                                   CommonValidList<TaskIdParam> taskIdParamList) {
        taskService.delete(taskIdParamList);
        return CommonResult.ok();
    }

    /**
     * 获取任务表详情
     *
     * @author H
     * @date  2025/11/19 14:24
     */
    @ApiOperationSupport(order = 5)
    @ApiOperation("获取任务表详情")
    @SaCheckPermission("/biz/task/detail")
    @GetMapping("/biz/task/detail")
    public CommonResult<Task> detail(@Valid TaskIdParam taskIdParam) {
        return CommonResult.data(taskService.detail(taskIdParam));
    }

    /**
     * 分管领导任务审核
     *
     * @author H
     * @date  2025/11/19 14:24
     */
    @ApiOperationSupport(order = 6)
    @ApiOperation("分管领导任务审核")
    @CommonLog("分管领导任务审核")
    @PostMapping("/biz/task/chargeAudit")
    public CommonResult<String> chargeAudit(@RequestBody @Valid TaskAuditReq taskAuditReq) {
        taskService.chargeAudit(taskAuditReq);
        return CommonResult.ok();
    }

    /**
     * 添加指派人员
     *
     * @author H
     * @date  2025/11/19 14:24
     */
    @ApiOperationSupport(order = 7)
    @ApiOperation("添加指派人员")
    @CommonLog("添加指派人员")
    @PostMapping("/biz/task/assignmentUser")
    public CommonResult<String> assignmentUser(@RequestBody @Valid AssigmentUserReq assigmentUserReq) {
        taskService.assignmentUser(assigmentUserReq);
        return CommonResult.ok();
    }

    /**
     * 评判任务
     *
     * @author H
     * @date  2025/11/19 14:24
     */
    @ApiOperationSupport(order = 8)
    @ApiOperation("评判任务")
    @CommonLog("评判任务")
    @PostMapping("/biz/task/taskJudge")
    public CommonResult<String> taskJudge(@RequestBody @Valid TaskJudgeReq taskJudgeReq) {
        taskService.taskJudge(taskJudgeReq);
        return CommonResult.ok();
    }

    /**
     * 获取任务审核记录表分页
     *
     * @author H
     * @date  2025/11/19 14:24
     */
    @ApiOperationSupport(order = 9)
    @ApiOperation("获取任务审核记录表分页")
    @GetMapping("/biz/task/pageAuditRecord")
    public CommonResult<Page<TaskAuditRecord>> pageAuditRecord(TaskAuditRecordPageParam taskAuditRecordPageParam) {
        return CommonResult.data(taskAuditRecordService.page(taskAuditRecordPageParam));
    }

    /**
     * 获取任务申请记录表分页
     *
     * @author H
     * @date  2025/11/19 14:24
     */
    @ApiOperationSupport(order = 10)
    @ApiOperation("获取任务申请记录表分页")
    @GetMapping("/biz/task/pageTaskAssigment")
    public CommonResult<Page<TaskAssigmentUser>> pageTaskAssigment(TaskAssignmentPageParam taskAssignmentPageParam) {
        return CommonResult.data(taskAssignmentService.pageTaskAssigment(taskAssignmentPageParam));
    }

    /**
     * 获取盯防任务日志表分页
     *
     * @author H
     * @date  2025/11/19 14:24
     */
    @ApiOperationSupport(order = 11)
    @ApiOperation("获取盯防任务日志表分页")
    @GetMapping("/biz/task/pageTaskLog")
    public CommonResult<Page<TaskLog>> pageTaskLog(TaskLogPageParam taskLogPageParam) {
        return CommonResult.data(taskLogService.page(taskLogPageParam));
    }

    /**
     * 发放奖励
     *
     * @author H
     * @date  2025/11/19 14:24
     */
    @ApiOperationSupport(order = 12)
    @ApiOperation("发放奖励")
    @CommonLog("发放奖励")
    @PostMapping("/biz/task/issueReward")
    public CommonResult<String> issueReward(@RequestBody @Valid TaskIdParam taskIdParam) {
        taskService.issueReward(taskIdParam);
        return CommonResult.ok();
    }
}
